﻿using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows.Forms;
using WindGoes6.Data;

namespace TestProject.TestForms
{
    public partial class ConfigAccessTestForm : Form
    {
        ConfigAccess ca = new ConfigAccess();

        public ConfigAccessTestForm()
        {
            InitializeComponent();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            ca.Load();
            txtInfo.Text = ca.GetString("Info");
            txtContent.Text = ca.GetString("Content");
            ckSelected.Checked = ca.GetBoolean("Selected", false);
            numValue1.Value = (decimal)ca.GetDouble("Value", 0);

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("M101.V1: " + ca.GetString("M101", "V1"));
            sb.AppendLine("模块2.用户上限: " + ca.GetString("模块2", "用户上限"));

            txtOutput.Text = sb.ToString();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            ca.SetValue("Info", txtInfo.Text);
            ca.SetValue("Content", txtContent.Text);
            ca.SetBoolean("Selected", ckSelected.Checked);
            ca.SetValue("Value", numValue1.Value);
            ca.SetValue("M101", "V1", "12345");
            ca.SetValue("模块2", "用户上限", "1500");
            ca.Save();
        }

        private void ConfigAccessTestForm_Load(object sender, EventArgs e)
        {
            txtConfigPath.Text  = Path.GetFullPath(txtConfigPath.Text);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnShowInExplorer_Click(object sender, EventArgs e)
        {
            Process.Start("explorer", $"/select,\"{txtConfigPath.Text}\"");
        }

        private void btnClearAll_Click(object sender, EventArgs e)
        {
            txtInfo.Clear();
            txtContent.Clear();
        }
    }
}
